package com.shen;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/3.
 * Function:
 */
public class demo06 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy:MM:dd");
        FileWriter fileWriter=null;
        BufferedWriter bufferedWriter=null;
        try {
            boolean flag=true;
            fileWriter=new FileWriter("E:/a/b/a.txt");
            bufferedWriter=new BufferedWriter(fileWriter);

            while (flag){
                System.out.println("请在控制台输入一行：");
                String input=scanner.nextLine();
                if("quit".equals(input)){
                  flag=false;
                }else{
                    bufferedWriter.write(simpleDateFormat.format(new Date())+" ");
                    bufferedWriter.write(input);
                    bufferedWriter.newLine();
                }
            }
            bufferedWriter.flush();


        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(fileWriter!=null){
                    fileWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
